package comlile.string;

/*
 * String s = new String(“hello”)和String s = “hello”;的区别
 * 
 * ==:比较引用类型，比较的是地址值
 * equal():默认比较的是地址值。String类重写了equals()方法，该方法的作用是比较字符串的内容是否相同
 */
public class _02StringCompare {

	public static void main(String[] args) {
		String s1 = new String("hello");
		String s2 = "hello";

		System.out.println(s1 == s2); // false
		System.out.println(s1.equals(s2)); // true
		
		System.out.println("/************************/");
		compareTest();
	}
	
	/*
	 * 看程序写结果
	 * 字符串变量相加：先开空间，再加内容
	 * 字符串常量相加：先加，再找，没有再开空间
	 */
	static void compareTest()
	{
		String s1 = "hello";
		String s2 = "world";
		String s3 = "helloworld";
		String s4 = s1 + s2;
		String s5 = "hello"+"world";
		System.out.println(s4);
		System.out.println(s5);
		System.out.println(s3 == s1 + s2);// false
		System.out.println(s3.equals(s1 + s2));// true
		System.out.println(s3 == "hello" + "world");// true

	}

}
